<?php
require('connect.php');
include 'constants.php';

if (!isset($_POST['type']))
{
	return;
}

$type = intval($_POST['type']);
$isPuzzle = $_POST['is_puzzle'];
if($isPuzzle == "true") $isPuzzle = true; else $isPuzzle = false;
$topN = 10;

//query for getting topN'th score (if there is no N scores, nothing is returned)
$rankQuery = "SELECT type, rank, time, username, level
FROM (
SELECT @rownum:=@rownum+1 AS rank,type, username, time, user_id, level
FROM world_records, (SELECT @rownum:=0) r
WHERE type = '" . $type . "'";
$rankQuery .= getOrder($type,$isPuzzle);
$rankQuery .= ") u WHERE u.rank = '" . $topN . "'";

$result = mysql_query($rankQuery);
if (mysql_num_rows($result) > 0)
{
	$row = mysql_fetch_assoc($result);
	echo json_encode($row);
}

mysql_close();
